package com.uzai.console.web.wechatwork;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.uzai.common.enums.DeviceTypeEnum;
import com.uzai.console.annotation.SystemLogType;
import com.uzai.console.common.utils.Tools;
import com.uzai.console.dto.device.DeviceQuery;
import com.uzai.console.dto.wechatwork.wxq.rule.WxWorkGroupRuleBatchSetDto;
import com.uzai.console.dto.wechatwork.wxq.rule.WxWorkGroupRuleSetDto;
import com.uzai.console.dto.wechatwork.wxq.rule.WxqWorkGroupRuleFindListDto;
import com.uzai.console.dto.wechatwork.wxq.rule.WxqWorkGroupRuleRefleshDto;
import com.uzai.console.dto.wechatwork.wxq.welcome.*;
import com.uzai.console.dto.wechatwork.wxq.wxgroup.*;
import com.uzai.console.enums.OperationTypeEnum;
import com.uzai.console.enums.SystemModelEnum;
import com.uzai.console.service.device.DeviceService;
import com.uzai.console.service.wechatwork.WxWorkGroupService;
import com.uzai.console.service.wechatwork.WxWorkGroupSyncService;
import com.uzai.console.vo.device.DeviceInfoVo;
import com.uzai.console.vo.wechatwork.wxq.managerfunc.WxqWorkGroupManagerFuncVo;
import com.uzai.console.vo.wechatwork.wxq.rule.WxWorkGroupRuleVo;
import com.uzai.console.vo.wechatwork.wxq.welcome.WxWorkGroupWelcomeVo;
import com.uzai.console.vo.wechatwork.wxq.wxgroup.WxWorkGroupInfoVo;
import com.uzai.console.vo.wechatwork.wxq.wxgroup.WxWorkGroupQrcodeVo;
import com.uzai.console.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 微信群
 *
 * @author liuqi
 * @date 2021年08月16日 15:11
 */
@Api(value = "企业微信微信群", tags = "企业微信|微信群")
@ApiSort(6)
@RestController
public class WxWorkGroupController extends BaseController {
    private Logger logger = LoggerFactory.getLogger(WxWorkGroupController.class);

    @Autowired
    private WxWorkGroupService wxWorkGroupService;
    @Autowired
    private DeviceService deviceService;
    @Autowired
    private WxWorkGroupSyncService wxWorkGroupSyncService;

    @ApiOperation(value = "查询企业微信群列表", notes = "查询企业微信群列表", response = WxWorkGroupInfoVo.class)
    @ApiOperationSupport(order = 1)
    @PostMapping("/wxWorkGroup/findWxWorkGroupList")
    public Object findWxWorkGroupList(@RequestBody WxWorkGroupQuery wxWorkGroupQuery) {
        return wxWorkGroupService.findWxWorkGroupList(wxWorkGroupQuery);
    }

    @ApiOperation(value = "查询企业微信微信群详情", response = WxWorkGroupInfoVo.class)
    @ApiOperationSupport(order = 2)
    @PostMapping("/wxWorkGroup/findWxWorkGroupInfo")
    public Object findWxWorkGroupInfo(@RequestBody WxWorkGroupIdDto wxWorkGroupIdDto) {
        return wxWorkGroupService.findWxWorkGroupInfo(wxWorkGroupIdDto);
    }

    @SystemLogType(model = SystemModelEnum.WxWorkGroupInfo, type = OperationTypeEnum.QUIT)
    @ApiOperation(value = "退出企业微信群", notes = "退出企业微信群")
    @ApiOperationSupport(order = 2)
    @PostMapping("/wxWorkGroup/quitWxWorkGroup")
    public Object quitWxWorkGroup(@RequestBody WxWorkGroupIdDto wxWorkGroupIdDto) {
        wxWorkGroupService.quitWxWorkGroup(wxWorkGroupIdDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.WxWorkGroupInfo, type = OperationTypeEnum.QUIT)
    @ApiOperation(value = "批量退出企业微信群", notes = "批量退出企业微信群")
    @ApiOperationSupport(order = 2)
    @PostMapping("/wxWorkGroup/quitWxWorkGroupBatch")
    public Object quitWxWorkGroupBatch(@RequestBody WxWorkGroupIdListDto wxWorkGroupIdListDto) {
        wxWorkGroupSyncService.quitWxWorkGroupBatch(wxWorkGroupIdListDto);
        return true;
    }

    @ApiOperation(value = "查询机器人列表", notes = "查询机器人列表", response = DeviceInfoVo.class)
    @ApiOperationSupport(order = 3)
    @PostMapping("/wxWorkGroup/findDeviceList")
    public Object findDeviceList() {
        DeviceQuery deviceQuery = new DeviceQuery();
        deviceQuery.setDeviceType(DeviceTypeEnum.DT_PC_WECHAT.getKey());
        deviceQuery.setMerId(getLoginInfo().getMerId());
        return deviceService.findDeviceList(deviceQuery);
    }

    @SystemLogType(model = SystemModelEnum.WxWorkGroupInfo, type = OperationTypeEnum.SENDMESSAGE)
    @ApiOperation(value = "发送消息", notes = "发送消息")
    @ApiOperationSupport(order = 4)
    @PostMapping("/wxWorkGroup/sendMessage")
    public Object sendMessage(@RequestBody WxWorkGroupSendMessageDto wxWorkGroupSendMessageDto) {
        wxWorkGroupService.sendMessage(wxWorkGroupSendMessageDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.WxWorkGroupInfo, type = OperationTypeEnum.SENDMESSAGE)
    @ApiOperation(value = "批量发送消息", notes = "批量发送消息")
    @ApiOperationSupport(order = 4)
    @PostMapping("/wxWorkGroup/sendMessageBatch")
    public Object sendMessage(@RequestBody WxWorkGroupSendMessageBatchDto wxWorkGroupSendMessageBatchDto) {
        wxWorkGroupSyncService.sendMessageBatch(wxWorkGroupSendMessageBatchDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.WxWorkGroupInfo, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "修改企业微信管理方案（弃用）", notes = "修改企业微信管理方案（弃用）")
    @ApiOperationSupport(order = 5)
    @PostMapping("/wxWorkGroup/updateManagePlan")
    public Object updateManagePlan(@RequestBody WxWorkGroupUpdateManagePlanDto wxWorkGroupUpdateManagePlanDto) {
        wxWorkGroupService.updateManagePlan(wxWorkGroupUpdateManagePlanDto);
        try {
            Thread.sleep(1000);
        } catch (Exception e) {

        }
        return true;
    }

    @SystemLogType(model = SystemModelEnum.WxWorkGroupInfo, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "批量修改企业微信管理方案", notes = "批量修改企业微信管理方案")
    @ApiOperationSupport(order = 5)
    @PostMapping("/wxWorkGroup/batchUpdateManagePlan")
    public Object batchUpdateManagePlan(@RequestBody WxWorkGroupBatchUpdateManagePlanDto wxWorkGroupBatchUpdateManagePlanDto) {
        wxWorkGroupService.batchUpdateManagePlan(wxWorkGroupBatchUpdateManagePlanDto);

        try {
            Thread.sleep(1000);
        } catch (Exception e) {

        }

        return true;
    }

    @ApiOperation(value = "刷新企业微信群成员", notes = "刷新企业微信群成员")
    @ApiOperationSupport(order = 6)
    @PostMapping("/wxWorkGroup/refreshGroupMember")
    public Object refreshGroupMember(@RequestBody WxWorkGroupIdDto wxWorkGroupIdDto) {
        wxWorkGroupService.refreshGroupMember(wxWorkGroupIdDto);
        return true;
    }

    @ApiOperation(value = "批量刷新企业微信群成员", notes = "批量刷新企业微信群成员")
    @ApiOperationSupport(order = 7)
    @PostMapping("/wxWorkGroup/refreshGroupMemberBatch")
    public Object refreshGroupMemberBatch(@RequestBody WxWorkGroupIdListDto wxWorkGroupIdListDto) {
        wxWorkGroupSyncService.refreshGroupMemberBatch(wxWorkGroupIdListDto);
        return true;
    }

    @ApiOperation(value = "查询企业微信已经配置了管理方案的微信群列表", notes = "查询企业微信已经配置了管理方案的微信群列表", response = WxWorkGroupInfoVo.class)
    @ApiOperationSupport(order = 8)
    @PostMapping("/wxWorkGroup/findWxqGroupManagePlanList")
    public Object findWxqGroupManagePlanList(@RequestBody WxWorkGroupQuery wxWorkGroupQuery) {
        //return wxWorkGroupService.findWxqWorkGroupManagePlanList(wxqWorkGroupManagePlanQuery);
        wxWorkGroupQuery.setManagePlanIdFlag(1);//开启过滤未配置管理方案
        //如果开启了wxid过滤
        if (Tools.getInteger(wxWorkGroupQuery.getWxidDistinctFlag()).intValue() == 1) {
            wxWorkGroupQuery.setManagePlanIdFlag(null);//不需要开启过滤未配置管理方案
        }
        return wxWorkGroupService.findWxWorkGroupList(wxWorkGroupQuery);
    }


    @ApiOperation(value = "企业微信修改群昵称", notes = "企业微信修改群昵称")
    @ApiOperationSupport(order = 9)
    @PostMapping("/wxWorkGroup/nickName/update")
    public Object updateWxWorkGroupNickName(@RequestBody WxWorkGroupUpdateNicknameDto wxWorkGroupUpdateNicknameDto) {
        wxWorkGroupService.updateWxWorkGroupNickName(wxWorkGroupUpdateNicknameDto);
        return true;
    }

    @ApiOperation(value = "企业微信创建群", notes = "修改企业微信群昵称")
    @ApiOperationSupport(order = 10)
    @PostMapping("/wxWorkGroup/create")
    public Object createWxWorkGroup(@RequestBody WxWorkGroupCreateDto wxWorkGroupCreateDto) {
        wxWorkGroupService.createWxWorkGroup(wxWorkGroupCreateDto);
        return true;
    }

    @ApiOperation(value = "企业微信邀请进群", notes = "企业微信邀请进群")
    @ApiOperationSupport(order = 11)
    @PostMapping("/wxWorkGroup/invite")
    public Object inviteWxWorkGroup(@RequestBody WxWorkGroupInviteDto wxWorkGroupInviteDto) {
        wxWorkGroupService.inviteWxWorkGroup(wxWorkGroupInviteDto);
        return true;
    }

    @ApiOperation(value = "企业微信批量邀请进群", notes = "企业微信批量邀请进群")
    @ApiOperationSupport(order = 11)
    @PostMapping("/wxWorkGroup/batchInvite")
    public Object batchInviteWxWorkGroup(@RequestBody WxWorkGroupBatchInviteDto wxWorkGroupBatchInviteDto) {
        wxWorkGroupService.batchInviteWxWorkGroup(wxWorkGroupBatchInviteDto);
        return true;
    }

    @ApiOperation(value = "企业微信查询群二维码", notes = "企业微信查询群二维码", response = WxWorkGroupQrcodeVo.class)
    @ApiOperationSupport(order = 12)
    @PostMapping("/wxWorkGroup/qrcode/find")
    public Object findQrcode(@RequestBody WxWorkGroupQrcodeDto wxWorkGroupQrcodeDto) {
        return wxWorkGroupService.findQrcode(wxWorkGroupQrcodeDto);
    }

    @ApiOperation(value = "企业微信申请群二维码", notes = "企业微信获取群二维码")
    @ApiOperationSupport(order = 13)
    @PostMapping("/wxWorkGroup/qrcode/apply")
    public Object applyQrcode(@RequestBody WxWorkGroupQrcodeDto wxWorkGroupQrcodeDto) {
        wxWorkGroupService.applyQrcode(wxWorkGroupQrcodeDto);
        return true;
    }

    @ApiOperation(value = "企业微信发送群公告", notes = "企业微信发送群公告")
    @ApiOperationSupport(order = 14)
    @PostMapping("/wxWorkGroup/notice/send")
    public Object sendnotice(@RequestBody WxWorkGroupSendNoticeDto wxWorkGroupSendNoticeDto) {
        wxWorkGroupService.sendNotice(wxWorkGroupSendNoticeDto);
        return true;
    }

    @ApiOperation(value = "企业微信批量发送群公告", notes = "企业微信批量发送群公告")
    @ApiOperationSupport(order = 14)
    @PostMapping("/wxWorkGroup/notice/batchSend")
    public Object batchSendNotice(@RequestBody WxWorkGroupBatchSendNoticeDto wxWorkGroupBatchSendNoticeDto) {
        wxWorkGroupService.batchSendNotice(wxWorkGroupBatchSendNoticeDto);
        return true;
    }

    @ApiOperation(value = "企业微信查询群管功能", notes = "企业微信查询群管功能", response = WxqWorkGroupManagerFuncVo.class)
    @ApiOperationSupport(order = 14)
    @PostMapping("/wxWorkGroup/managerFunc/find")
    public Object findManagerFunc(@RequestBody WxWorkGroupIdDto wxWorkGroupIdDto) {
        return wxWorkGroupService.findManagerFunc(wxWorkGroupIdDto);
    }

    @ApiOperation(value = "企业微信设置群管功能", notes = "企业微信设置群管功能")
    @ApiOperationSupport(order = 14)
    @PostMapping("/wxWorkGroup/managerFunc/set")
    public Object setManagerFunc(@RequestBody WxWorkGroupSetManagerFuncDto wxWorkGroupSetManagerFuncDto) {
        wxWorkGroupService.setManagerFunc(wxWorkGroupSetManagerFuncDto);
        return true;
    }

    @ApiOperation(value = "企业微信批量设置群管功能", notes = "企业微信批量设置群管功能")
    @ApiOperationSupport(order = 14)
    @PostMapping("/wxWorkGroup/managerFunc/batchSet")
    public Object batchSetManagerFunc(@RequestBody WxWorkGroupBatchSetManagerFuncDto wxWorkGroupBatchSetManagerFuncDto) {
        wxWorkGroupService.batchSetManagerFunc(wxWorkGroupBatchSetManagerFuncDto);
        return true;
    }

    @ApiOperation(value = "企业微信解散本群", notes = "企业微信解散本群")
    @ApiOperationSupport(order = 15)
    @PostMapping("/wxWorkGroup/delete")
    public Object deleteWxWorkGroup(@RequestBody WxWorkGroupIdDto wxWorkGroupIdDto) {
        wxWorkGroupService.deleteWxWorkGroup(wxWorkGroupIdDto);
        return true;
    }

    @ApiOperation(value = "企业微信退出本群", notes = "企业微信退出本群")
    @ApiOperationSupport(order = 16)
    @PostMapping("/wxWorkGroup/quite")
    public Object quiteWxWorkGroup(@RequestBody WxWorkGroupIdDto wxWorkGroupIdDto) {
        wxWorkGroupService.quiteWxWorkGroup(wxWorkGroupIdDto);
        return true;
    }

    @ApiOperation(value = "企业微信刷新群成员", notes = "企业微信刷新群成员")
    @ApiOperationSupport(order = 18)
    @PostMapping("/wxWorkGroup/refreshMember")
    public Object refreshMember(@RequestBody WxWorkGroupIdDto wxWorkGroupIdDto) {
        wxWorkGroupService.refreshMember(wxWorkGroupIdDto);
        return true;
    }

    @ApiOperation(value = "企业微信查询欢迎语列表", notes = "企业微信查询欢迎语列表", response = WxWorkGroupWelcomeVo.class)
    @ApiOperationSupport(order = 19)
    @PostMapping("/wxWorkGroup/welcome/list")
    public Object findWelcomeList(@RequestBody WxqWorkGroupWelcomeFindListDto wxqWorkGroupWelcomeFindListDto) {
        return wxWorkGroupService.findWelcomeList(wxqWorkGroupWelcomeFindListDto);
    }

    @ApiOperation(value = "企业微信同步欢迎语", notes = "企业微信同步欢迎语")
    @ApiOperationSupport(order = 20)
    @PostMapping("/wxWorkGroup/welcome/refresh")
    public Object refreshWelcome(@RequestBody WxqWorkGroupWelcomeRefleshDto wxqWorkGroupWelcomeRefleshDto) {
        wxWorkGroupService.refreshWelcome(wxqWorkGroupWelcomeRefleshDto);
        return true;
    }

    @ApiOperation(value = "企业微信添加欢迎语", notes = "企业微信添加欢迎语")
    @ApiOperationSupport(order = 21)
    @PostMapping("/wxWorkGroup/welcome/add")
    public Object addWelcome(@RequestBody WxWorkGroupWelcomeAddDto wxWorkGroupWelcomeAddDto) {
        wxWorkGroupService.addWelcome(wxWorkGroupWelcomeAddDto);
        return true;
    }

    @ApiOperation(value = "企业微信批量添加欢迎语", notes = "企业微信批量添加欢迎语")
    @ApiOperationSupport(order = 21)
    @PostMapping("/wxWorkGroup/welcome/batchAdd")
    public Object batchAdd(@RequestBody WxWorkGroupWelcomeBatchAddDto wxWorkGroupWelcomeBatchAddDto) {
        wxWorkGroupService.batchAddWelcome(wxWorkGroupWelcomeBatchAddDto);
        return true;
    }

    @ApiOperation(value = "企业微信设置欢迎语", notes = "企业微信设置欢迎语")
    @ApiOperationSupport(order = 21)
    @PostMapping("/wxWorkGroup/welcome/set")
    public Object setWelcome(@RequestBody WxWorkGroupWelcomeSetDto wxWorkGroupWelcomeSetDto) {
        wxWorkGroupService.setWelcome(wxWorkGroupWelcomeSetDto);
        return true;
    }

    @ApiOperation(value = "企业微信批量设置欢迎语", notes = "企业微信批量设置欢迎语")
    @ApiOperationSupport(order = 21)
    @PostMapping("/wxWorkGroup/welcome/batchSet")
    public Object batchSetWelcome(@RequestBody WxWorkGroupWelcomeBatchSetDto wxWorkGroupWelcomeBatchSetDto) {
        wxWorkGroupService.batchSetWelcome(wxWorkGroupWelcomeBatchSetDto);
        return true;
    }

    @ApiOperation(value = "企业微信查询防骚扰规则列表", notes = "企业微信查询防骚扰规则列表", response = WxWorkGroupRuleVo.class)
    @ApiOperationSupport(order = 22)
    @PostMapping("/wxWorkGroup/rule/list")
    public Object findRuleList(@RequestBody WxqWorkGroupRuleFindListDto wxqWorkGroupRuleFindListDto) {
        return wxWorkGroupService.findRuleList(wxqWorkGroupRuleFindListDto);
    }

    @ApiOperation(value = "企业微信同步防骚扰规则", notes = "企业微信同步防骚扰规则")
    @ApiOperationSupport(order = 23)
    @PostMapping("/wxWorkGroup/rule/refresh")
    public Object refreshRuleList(@RequestBody WxqWorkGroupRuleRefleshDto wxqWorkGroupRuleRefleshDto) {
        wxWorkGroupService.refreshRule(wxqWorkGroupRuleRefleshDto);
        return true;
    }

    @ApiOperation(value = "企业微信设置防骚扰规则", notes = "企业微信设置防骚扰规则")
    @ApiOperationSupport(order = 24)
    @PostMapping("/wxWorkGroup/rule/set")
    public Object setRule(@RequestBody WxWorkGroupRuleSetDto wxWorkGroupRuleSetDto) {
        wxWorkGroupService.setRule(wxWorkGroupRuleSetDto);
        return true;
    }

    @ApiOperation(value = "企业微信批量设置防骚扰规则", notes = "企业微信批量设置防骚扰规则")
    @ApiOperationSupport(order = 24)
    @PostMapping("/wxWorkGroup/rule/batchSet")
    public Object batchSetRule(@RequestBody WxWorkGroupRuleBatchSetDto wxWorkGroupRuleBatchSetDto) {
        wxWorkGroupService.batchSetRule(wxWorkGroupRuleBatchSetDto);
        return true;
    }

    @ApiOperation(value = "企业微信批量踢出群成员", notes = "企业微信批量踢出群成员")
    @ApiOperationSupport(order = 24)
    @PostMapping("/wxWorkGroup/batchKickWxWorkGroupMember")
    public Object batchKickWxWorkGroupMember(@RequestBody BatchKickWxWorkGroupMemberDto batchKickWxWorkGroupMemberDto) {
        wxWorkGroupService.batchKickWxWorkGroupMember(batchKickWxWorkGroupMemberDto);
        return true;
    }


    @SystemLogType(model = SystemModelEnum.DeviceWechatWxGroup, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "修改企业微信群备注", notes = "修改企业微信群备注")
    @ApiOperationSupport(order = 25)
    @PostMapping("/wxWorkGroup/updateRemark")
    public Object updateRemark(@RequestBody WxWorkGroupUpdateRemarkDto wxWorkGroupUpdateRemarkDto) {
        wxWorkGroupService.updateRemark(wxWorkGroupUpdateRemarkDto);
        return true;
    }


    @ApiOperation(value = "企业微信批量添加群管理员", notes = "企业微信批量添加群管理员")
    @ApiOperationSupport(order = 26)
    @PostMapping("/wxWorkGroup/batchAddManager")
    public Object batchAddManager(@RequestBody BatchAddManagerDto batchAddManagerDto){
        wxWorkGroupService.batchAddManager(batchAddManagerDto);
        return true;
    }

}
